﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.Store.Goods
{
    public partial class First : System.Web.UI.Page
    {
        BLL.V_Goods bllV_Goods = new BLL.V_Goods();
        //
        BLL.Goods_Stat bllGoods_Stat = new BLL.Goods_Stat();
        protected void Page_Load(object sender, EventArgs e)
        {
            string sqlBase = "DateType=2 and RowID>0";
            //销量
            string GoodsIDStr_Orders_GoodsAmoun = GetGoodsIDStr(bllGoods_Stat.GetList(4, sqlBase, " Orders_GoodsAmoun desc"));
            if (GoodsIDStr_Orders_GoodsAmoun != "")
            {
                rp_Orders_GoodsAmoun.DataSource = GetListGoods(GoodsIDStr_Orders_GoodsAmoun);
                rp_Orders_GoodsAmoun.DataBind();
            }
            //销售额
            string GoodsIDStr_SellPrice = GetGoodsIDStr(bllGoods_Stat.GetList(4, sqlBase, " SellPrice desc"));
            if (GoodsIDStr_SellPrice != "")
            {
                rp_SellPrice.DataSource = GetListGoods(GoodsIDStr_SellPrice);
                rp_SellPrice.DataBind();
            }
            //活动
            string sql_SellWay = " id in ";
            sql_SellWay += " (select GoodsID from Goods_SaleWay_Discount where  DiscountSell<100 and DateFrom<=getdate() and DateTo>=getdate() ) or";
            sql_SellWay += " id in ";
            sql_SellWay += " (select GoodsID from Goods_SaleWay_GiftNumber where  GiftNumberSell>0 and  DateFrom<=getdate() and DateTo>=getdate() ) ";
            rp_SellWay.DataSource = bllV_Goods.GetList(4, sql_SellWay, "id desc");
            rp_SellWay.DataBind();
        }
        string GetGoodsIDStr(DataSet ds_)
        {
            string returnVal = "";
            if (ds_ != null && ds_.Tables.Count > 0 && ds_.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds_.Tables[0].Rows)
                {
                    if (returnVal != "") returnVal += ",";
                    returnVal += dr["RowID"];
                }
            }
            return returnVal;
        }
        List<Model.V_Goods> GetListGoods(string GoodsIDstr_)
        {
            string _sql= "id in (" + GoodsIDstr_ + ") order by CHARINDEX(','+CONVERT(varchar(10),ID)+',','," + GoodsIDstr_ + ",')";
            return bllV_Goods.GetModelList(_sql);
        }
    }
}